package vistas;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import beans.FacturaBean;
import beans.RodamientoBean;
import controller.ControllerPrincipal;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class DetalleFactura extends BaseJFrame {

	private JList listaRodamientos;
	private DefaultListModel listModel = new DefaultListModel();
	private FacturaBean factura;
	private JLabel jLDetalleFact;
	private JTextField jTextImporte;
	private JLabel jLImporte;
	private JButton jButtonSalir;
	private float importe = 0;
	private JTextField jTextNroFact;
	private JLabel jLabelNroFactura;

	public DetalleFactura(FacturaBean fb) {
		super();
		this.factura = fb;
		initGUI();
	}

	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
			}
			{
				listaRodamientos = new JList(listModel);
				getContentPane().add(listaRodamientos);
				// listaFacturas.setBounds(89, 54, 163, 113);
				JScrollPane listScroller = new JScrollPane(listaRodamientos);
				listScroller.setBounds(27, 58, 331, 156);
				getContentPane().add(listScroller);
				// poner rodamientos
				for (RodamientoBean rb : factura.getReferencia()
						.getRodamientos()) {
					importe = importe + rb.getPrecio();
					listModel.addElement(rb);
				}
			}
			{
				jLDetalleFact = new JLabel();
				getContentPane().add(jLDetalleFact);
				jLDetalleFact.setText("Detalle de Factura");
				jLDetalleFact.setBounds(134, 12, 105, 15);
			}
			{
				jButtonSalir = new JButton();
				getContentPane().add(jButtonSalir);
				jButtonSalir.setText("Salir");
				jButtonSalir.setBounds(161, 256, 43, 22);
				jButtonSalir.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						_exit();
					}
				});
			}
			{
				jLImporte = new JLabel();
				getContentPane().add(jLImporte);
				jLImporte.setText("Importe Total: ");
				jLImporte.setBounds(75, 226, 86, 15);
			}
			{
				jTextImporte = new JTextField();
				jTextImporte.setText(importe + "");
				getContentPane().add(jTextImporte);
				jTextImporte.setBounds(187, 223, 90, 22);
			}
			{
				jLabelNroFactura = new JLabel();
				getContentPane().add(jLabelNroFactura);
				jLabelNroFactura.setText("Numero de Factura: ");
				jLabelNroFactura.setBounds(32, 38, 119, 15);
			}
			{
				jTextNroFact = new JTextField();
				jTextNroFact.setText(factura.getNumero() + "");
				getContentPane().add(jTextNroFact);
				jTextNroFact.setBounds(161, 35, 95, 22);
			}
			{
				this.setSize(381, 311);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private void _exit() {
		this.dispose();
	}
}
